package com.cnsoft.model.communal2;

import javax.annotation.Resource;

import org.cnsoft.framework.beans.common.RESTResultBean;
import org.cnsoft.framework.constants.ECCodeMessageConstants;
import org.cnsoft.framework.db.page.PageModel;
import org.cnsoft.framework.support.MyPageControllerSupport;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cnsoft.persistent.communal2.R71a030GoodsClassify.R71a030GoodsClassifyDBO;
import com.cnsoft.persistent.communal2.R71a030GoodsClassify.R71a030GoodsClassifyDao;
import com.cnsoft.persistent.communal2.R71a030GoodsClassify.R71a030GoodsClassifyPVO;

/**
 * 商品明细分类表页面控制逻辑
 */
@Controller
@RequestMapping(value = "/page/1.0/base/r71a030goodsclassify", method = { RequestMethod.POST })
public class R71a030GoodsClassifyPageController extends MyPageControllerSupport { // MyTokenCommonSupport
	@Resource
	private R71a030GoodsClassifyDao daoR71a030GoodsClassify;

	// private MyModelAndViewSupport model =
	// super.getModelAndView("R71A030_goods_classify");

	// 一览（分页查询）
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public ModelAndView doList(R71a030GoodsClassifyPVO param, PageModel<R71a030GoodsClassifyDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/communal2/R71a030GoodsClassify-list");
		pageModel.setFormParamBean(param);
		// 开启记录数统计
		// pageModel.setResultCountFlag(true);
		// 排序模式
		// pageModel.setOrderbyCreateTimeDESC();
		// 分页查询
		daoR71a030GoodsClassify.doSelectPage(pageModel);
		// 设定返回
		modelAndView.addObject("page", pageModel);
		modelAndView.addObject("param", param);
		modelAndView.addObject("message", message);
		return modelAndView;
	}

	// 打开新增页面
	@RequestMapping(value = "/append", method = RequestMethod.POST)
	public ModelAndView doAppend(R71a030GoodsClassifyPVO param, PageModel<R71a030GoodsClassifyDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/communal2/R71a030GoodsClassify-item");
		// 页面模式设定
		modelAndView.addObject("mode", ONE);
		return modelAndView;
	}

	// 打开编辑页面
	@RequestMapping(value = "/modify", method = RequestMethod.POST)
	public ModelAndView doModify(R71a030GoodsClassifyPVO param, PageModel<R71a030GoodsClassifyDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/communal2/R71a030GoodsClassify-item");
		// 页面模式设定
		modelAndView.addObject("mode", TWO);
		// 数据查询
		modelAndView.addObject("data", daoR71a030GoodsClassify.doRead(param));
		return modelAndView;
	}

	// 删除数据
	@RequestMapping(value = "/discard", method = RequestMethod.POST)
	public ModelAndView doDiscard(R71a030GoodsClassifyPVO param, PageModel<R71a030GoodsClassifyDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 信息删除
		daoR71a030GoodsClassify.doDelete(param);
		message.setResult(ECCodeMessageConstants.MESSAGE_DB_DELETE);
		return doList(new R71a030GoodsClassifyPVO(), pageModel, message);
	}

	// 数据保存
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView doSave(String mode, R71a030GoodsClassifyPVO param, PageModel<R71a030GoodsClassifyDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 判断操作类别
		if (ONE.equals(mode)) { // 新增
			daoR71a030GoodsClassify.doInsertSelective(param);
			message.setResult(ECCodeMessageConstants.MESSAGE_DB_INSERT);
		} else { // 编辑
			daoR71a030GoodsClassify.doUpdate(param);
			message.setResult(ECCodeMessageConstants.MESSAGE_DB_UPDATE);
		}
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/communal/pageform-saas");
		// 页面提示信息设定
		modelAndView.addObject("message", message);
		// 目标展示页面
		modelAndView.addObject("target", "/page/1.0/base/r71a030goodsclassify/list");
		return modelAndView;
	}

}
